package com.njg.juc.block;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @auther zzyybs@126.com
 * @Date 2025-04-24 14:18
 * @Description: TODO
 */
public class BlockingQueueDemo
{
    public static void main(String[] args) throws InterruptedException
    {
        //创建一个阻塞队列
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

        /*blockingQueue.add("a");
        blockingQueue.add("b");
        blockingQueue.add("c");
//        blockingQueue.add("d");

        System.out.println(blockingQueue.element());

        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());*/


        /*System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));
        System.out.println(blockingQueue.offer("d"));

        *//*System.out.println(blockingQueue.peek());
        System.out.println(blockingQueue.peek());
        System.out.println(blockingQueue.peek());*//*


        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());*/



        blockingQueue.put("a");
        blockingQueue.put("b");
        blockingQueue.put("c");

        System.out.println("11111"+blockingQueue.size());
//        blockingQueue.put("d");
        System.out.println("22222"+blockingQueue.size());


        blockingQueue.take();
        blockingQueue.take();
        blockingQueue.take();
        blockingQueue.put("d");
        System.out.println("33333"+blockingQueue.size());
        blockingQueue.take();
    }
}
